﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace iSystem
{
	public class iFileAssist
	{
        enum RecycleFlags : uint
        {
            SHERB_NOCONFIRMATION = 0x00000001, SHERB_NOPROGRESSUI = 0x00000001, SHERB_NOSOUND = 0x00000004
        }
		public static bool CheckExtension(String sFileName, String exe)
		{
            int nPos = sFileName.IndexOf(".");
            if (sFileName.IndexOf(exe, nPos) == -1)
                return false;
            return true;
		}
        public static bool RemoveTail(ref String srcName, String removeName)
        {
            int nPos = srcName.IndexOf(removeName);
            if (nPos == -1)
                return false;

            srcName = srcName.Remove(nPos);
            return true;
        }
		public static void RemoveExtension(int nStartIndex, ref String sFileName)
		{
			sFileName = sFileName.Remove( nStartIndex );
		}
		public static String RemoveExtension(String sFileName)
		{
			int nPos = sFileName.IndexOf(".");
			return sFileName.Remove( nPos );
		}
        public static bool DeleteToRecycle(string path)
        {
            if (!File.Exists(path))
                return false;
            Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(path,
            Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs,
            Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin);
            return true;

        }        
	}
}
